export class TableBase<T=any>{
  value: any;     //表头名称
  required:boolean; //表头必填
  reg:any; //正则
  label: string;  //icon按钮的文本
  key: string;    //对应的key
  type: string;   //默认为text文本，dictionary | img | custom | time
  order: number;  //排序
  controlType: string;   //控制显示的控件类型 
  scopedSlots: any;   //当type=custom时可自定义slot名称
  tag: Object;    //标签形式显示key对应当前值显示不同颜色标签
  colors: Object;    //显示不同颜色
  handle: handleBase;    //当key=actions是代表操作按钮handle里面是按钮集合
  class: any;     //附加calss样式
  icon: any;      //附加icon图标
  columns: any;   //antd表格列的配置描述
  style: any;   //自定义样式
  state: any; //当type=dictionary时@/filter/dictionary对应的key为state.filterName
  data: Array<any>;//自定义数据
  childrenKey: string; //子集table的key，从父集获取字段
  childrenColumns: Array<{title,dataIndex}>;  //子集table的显示字段
  disabled: any;  //禁用字段可以为showKey
  constructor(options: {
    value?: any,
    key?: string,
    required?:boolean,
    reg?:any,
    label?: string,
    type?: string,
    order?: number,
    controlType?: string,
    state?: any,
    scopedSlots?: any,
    tag?: any,
    colors?: any,
    handle?:any,
    class?:any,
    icon?:any,
    style?:any,
    columns?:any,
    data?:Array<any>,
    childrenKey?: string,
    childrenColumns?: Array<{title,dataIndex}>,
    disabled?: any,
  } = {}) {
    this.value = options.value;
    this.required = options.required || false;
    this.reg = options.reg || null;
    this.key = options.key || '';
    this.label = options.label || '';
    this.type = options.type || '';
    this.order = options.order === undefined ? 1 : options.order;
    this.controlType = options.controlType || '';
    this.state = options.state || {};
    this.scopedSlots = options.scopedSlots || null;
    this.tag = options.tag || null;
    this.colors = options.colors || null;
    this.handle = options.handle || [];
    this.class = options.class || [];
    this.icon = options.icon || '';
    this.style = options.style || {};
    this.columns = options.columns || {};
    this.data = options.data || null;
    this.childrenKey = options.childrenKey || '';
    this.childrenColumns = options.childrenColumns || null;
    this.disabled = options.disabled || false;
  }
}

export interface handleBase {
  type: string,      
  //url:跳转 | hint:提示弹层信息（有请求接口） | delete:删除按钮 | layer:弹层按钮（subject） | local:本地处理按钮（subject）
  url: string,         //当type=url时url为路由名称，其他情况为接口地址
  postType: string,    //接口类型type=hint时默认为post |  type=delete时默认为delete
  text: string,   //按钮文本
  class: string,  //按钮样式
  showKey: Array<Object>,   
  //控制按钮显示的条件，key为此条数据的字段，value为对应的值，如：[{ key:'state' ,value:1 ,invert: false }], 当此条数据的state:1时此按钮显示,如果invert为true就取反值
  params: Array<Object>,    
  //params为额外传参，key为需要的key名，value为当前数据对应key的值，如{ids: 'id'},结果为?ids=10
  state: any, 
  //state.key 为权限标识，是否显示 | state.assign 扩展参数 | state.hintData.title 提示按钮配置信息 | state.keyName 传参的指定key名
}

export class TextTable extends TableBase<string> {
  controlType = 'text';
  hidden:boolean;
  params:any;
  url:any;
  options:any;

  constructor(options: {} = {}) {
    super(options);
    this.controlType = (<any>options)['controlType'] || 'text';
    this.type = (<any>options)['type'] || '';
    this.hidden = (<any>options)['hidden'] || false;
    this.params = (<any>options)['params'] || [];
    this.url = (<any>options)['url'] || '';
    this.options = (<any>options)['options'] || [];
  }
}
